<template>
	<view class="drawgifts">
		<view v-for="(item,index) in list" :key="item.id" class="gift_cell" @click="goDrawResult(item.gifts_status)">
			<view v-if="item.gifts_status==1" class="gift_status_def">未领取</view>
			<view v-if="item.gifts_status==2" class="gift_status">已领取</view>
			<view class="gift_cell_content_box">
				<image class="gift_img" :src="picUrl+item.pic" mode="aspectFill"></image>
				<view class="ml-15">
					<view class="f-15">{{item.name}}</view>
				</view>
			</view>
			<view v-if="item.gifts_status==1" @click="goDrawResult(item.gifts_status)" class="gift_use_btn">{{item.gifts_name}}</view>
			<view v-if="item.gifts_status==2" class="gift_use_def_btn">{{item.gifts_name}}</view>
		</view>
		<view class="page_bottom_loading" :style="'padding-bottom:'+pdbottom+'rpx;'">{{loadingTitle}}
		</view>
	</view>
</template>

<script>
	import {
		getDrawGiftList,
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				params: {},
				list: [],
				current_page: '',
				last_page: '',
				total: 0,
				loadingTitle: '',
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
				pdbottom: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets.bottom :
					30,
			};
		},
		onShow() {

		},
		onLoad() {
			this.getDrawGiftList()
		},
		methods: {
			getDrawGiftList() {
				getDrawGiftList(this.params).then(res => {
					if (res.state == 1) {
						this.list = [...this.list, ...res.data.list]
						this.current_page = res.data.current_page
						this.last_page = res.data.last_page
						this.total = res.data.total
						if (this.list.length == 0) {
							this.loadingTitle = "- 暂无更多 -"
						}
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			goDrawResult(gifts_status) {
				if (gifts_status == 1) {
					uni.navigateTo({
						url: '/pages/draw/drawresult'
					})
				}
			}
		},
		onPullDownRefresh() {
			this.paramsc.page = 1
			this.listc = []
			this.getDrawGiftList()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.current_pagec < this.last_pagec) {
				this.paramsc.page = this.paramsc.page + 1
				this.getDrawGiftList()
			} else {
				if (this.listc.length > 0) {
					this.loadingTitlec = "- 已经到底了 -"
				} else {
					this.loadingTitlec = "- 暂无更多 -"
				}
			}
		},
		onShareAppMessage(res) {
			app.getShareTask()
			return {

			}
		},
		onShareTimeline: function() {
			app.getShareTask()
			return {

			}
		},
	}
</script>

<style lang="scss">
	.drawgifts {
		padding: 30rpx;

		.gift_cell {
			position: relative;
			margin-top: 40rpx;
			padding: 30rpx;
			border-radius: 8rpx;
			border: 1rpx solid #F1F1F1;

			.gift_status {
				top: 0;
				right: 0;
				z-index: 1;
				position: absolute;
				color: #ffffff;
				font-size: 18rpx;
				padding: 4rpx 6rpx;
				border-top-right-radius: 8rpx;
				background-color: #E94E4E;
			}

			.gift_status_def {
				top: 0;
				right: 0;
				z-index: 1;
				position: absolute;
				color: #ffffff;
				font-size: 18rpx;
				padding: 4rpx 6rpx;
				border-top-right-radius: 8rpx;
				background-color: #C5C5C5;
			}

			.gift_cell_content_box {
				display: flex;
				align-items: center;

				.gift_img {
					width: 255rpx;
					height: 150rpx;
				}

			}

			.gift_use_btn {
				position: absolute;
				right: 30rpx;
				bottom: 30rpx;
				color: #ffffff;
				font-size: 24rpx;
				width: 150rpx;
				height: 45rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 30rpx;
				background-color: #00A0DC;
				z-index: 1;
			}

			.gift_use_def_btn {
				position: absolute;
				right: 30rpx;
				bottom: 30rpx;
				color: #ffffff;
				font-size: 24rpx;
				width: 150rpx;
				height: 45rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 30rpx;
				background-color: #C5C5C5;
				z-index: 1;
			}
		}
	}
</style>